package cn.usian.service.imp;

import cn.usian.dao.UserMapper;
import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;



    @Override
    public void del(Long id) {
        userMapper.deleteById(id);
    }

    @Override
    public User findById(Long id) {
        return userMapper.selectById(id);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public List<User> findByName(String name) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (name!=null && name!=""){
            queryWrapper.like("name",name);
        }
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public Page<User> findAll(int current, int size) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        Page<User> page = new Page<>(current,size);
        Page<User>userPage=userMapper.selectPage(page,null);
        return userPage;
    }
}
